package com.seaboxdata.utils;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

/**
 * @author
 * @create 2021-05-24 15:39
 **/
public class TestYJGLJ {
    public static void main(String[] args) {
        /*String url = "https://10.253.102.197:80/api/exchange/QueryJyzSecSchmain";
        String appkey = "89oHQqwqFXprLag8S7IoEQSOvxDTDIBjkLX5nQF3U2s";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("content-type", "application/json");
        Map<String, String> params = new HashMap<String, String>();
        params.put("access_token", appkey);
        //params.put("xxx", xxxx);
        try {
            HttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(url);
            if (headers != null && headers.size() > 0) {
                Set keySet = headers.keySet();
                for (Object key : keySet) {
                    httpPost.addHeader(new BasicHeader((String) key, (String) headers.get(key)));
                }
            }
            List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
            if (params != null && params.size() > 0) {
                Set keySet = params.keySet();
                for (Object key : keySet) {
                    paramsList.add(new BasicNameValuePair((String) key, (String) params.get(key)));
                }
            }

            httpPost.setEntity(new UrlEncodedFormEntity(paramsList, "utf-8"));
            HttpResponse response = httpClient.execute(httpPost);
            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }*/


        HttpClient client = null;
        HttpPost request;
        List<Object> results = new ArrayList<>();
        try {
            client = new SSLClient();
            request = new HttpPost(new URI("https://10.253.102.197:80/api/exchange/QueryJyzSecSchmain"));
            request.addHeader(new BasicHeader("Content-Type","application/x-www-form-urlencoded"));
            List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
            paramsList.add(new BasicNameValuePair("access_token","89oHQqwqFXprLag8S7IoEQSOvxDTDIBjkLX5nQF3U2s"));
            request.setEntity(new UrlEncodedFormEntity(paramsList, "utf-8"));
            HttpResponse response = client.execute(request);
            int returncode = response.getStatusLine().getStatusCode();
            if (returncode == 200) {
                String result = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
